import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';

export const configuration = () =>
  ({
    rootRoleId: parseInt(process.env.ROOT_ROLE_ID || '1'),
    // 用于配置 SMTP 服务器的连接邮件服务
    // mailer: {
    //   host: 'smtp.qq.com',
    //   port: 465,
    //   auth: {
    //     user: '2357659811@qq.com',
    //     pass: 'ilzeodqlmscxecga',
    //   },
    //   secure: true, // or true using 443
    // },
    // jwt sign secret
    jwt: {
      secret: process.env.JWT_SECRET || 'hhhxl',
    },
    // typeorm config
    database: {
      type: 'mysql',
      host: process.env.MYSQL_HOST,
      port: Number.parseInt(process.env.MYSQL_PORT, 10),
      username: process.env.MYSQL_USERNAME,
      password: process.env.MYSQL_PASSWORD,
      database: process.env.MYSQL_DATABASE,
      entities: [__dirname + '/../**/entities/*.entity.{ts,js}'],
      migrations: ['dist/src/migrations/**/*.js'],
      autoLoadEntities: true, // 自动注册实体
      synchronize: true, // 生产环境要关闭
      timezone: '+08:00', // 时区
      cli: {
        migrationsDir: 'src/migrations',
      },
    } as MysqlConnectionOptions,
    // redis config
    redis: {
      host: process.env.REDIS_HOST,
      port: parseInt(process.env.REDIS_PORT, 10),
      password: process.env.REDIS_PASSWORD,
      db: process.env.REDIS_DB,
    },
    // 用于与七牛云存储进行交互
    // qiniu: {
    //   accessKey: process.env.QINIU_ACCESSKEY,
    //   secretKey: process.env.QINIU_SECRETKEY,
    //   domain: process.env.QINIU_DOMAIN,
    //   bucket: process.env.QINIU_BUCKET,
    //   zone: parseZone(process.env.QINIU_ZONE || 'Zone_z2'),
    //   access: (process.env.QINIU_ACCESS_TYPE as any) || 'public',
    // },
    // swagger config
    swagger: {
      enable: process.env.SWAGGER_ENABLE === 'true',
      path: process.env.SWAGGER_PATH,
      title: process.env.SWAGGER_TITLE,
      desc: process.env.SWAGGER_DESC,
      version: process.env.SWAGGER_VERSION,
    },
  } as const);
